﻿using UnityEngine;
using System.Collections;
namespace AssetBundleHelper{
	public class AssetsLoader{
		#region Static
		static AssetsLoader instance;
		public static AssetsLoader Instance{
			get{
				if (instance == null)
					instance = new AssetsLoader ();
				return instance;
			}
		}
		#endregion

		string getConfPath(string name){
			return LoadConf.ConfPath + name;
		}
		string LuaPath(string name){
			return getConfPath ("Android/Lua/" + name);
		}
		public void LoadWWW(string name,System.Action<WWW> callback,System.Action<WWW> downloadcallback){
			var url = LoadConf.AssetsBundlePath + name;
			WWWMgr.Instance.Load (url,downloadcallback, delegate(WWW obj) {
				callback(obj);
			});
		}
		public void LoadText(string name,System.Action<string> callback){
			var url = LoadConf.AssetsBundlePath + name;
			WWWMgr.Instance.Load (url, delegate(WWW obj) {
				callback(obj.text);
			});
		}
		public void LoadAB(string name,System.Action<AssetBundle> callback){
			var url = LoadConf.AssetsBundlePath + name;
			WWWMgr.Instance.Load (url, delegate(WWW obj) {
				callback(obj.assetBundle);
			});
		}

		public void LoadAssetBundleByVersion(string version, System.Action<WWW> downcallback,System.Action<string,string,float> processcallback,System.Action callback){
			var loader = new GameObject ("VersionLoader").AddComponent<AssetsVersionLoader> ();
			loader.Load (version,processcallback, callback,downcallback);
		}
	}
}